package com.dongdong.controller;


import com.alibaba.fastjson.JSONObject;
import com.dongdong.result.Result;
import com.dongdong.result.ResultEnums;
import com.dongdong.service.SeckillOrderService;
import com.dongdong.utils.JwtUtil;
import com.dongdong.vo.UserVO;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("seckillOrder")
public class SeckillOrderController {

    @Autowired
    private JwtUtil jwtUtil;

    @Autowired
    private SeckillOrderService seckillOrderService;

    @GetMapping("/submitSeckillOrder")
    public Result submitSeckillorder(@RequestParam Long id, @RequestHeader String token) {

        Claims claims = jwtUtil.parseJwt(token);
        String str = claims.getSubject();
        UserVO userVO = JSONObject.parseObject(str, UserVO.class);

        Result result = seckillOrderService.submitSeckillorder(id, userVO);
        return result;//秒杀成功

    }










}
